#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

class Solution {
public:
    vector<int> maxSlidingWindow(vector<int>& nums, int k) {
        deque<int> Q;
        vector<int> result;
        for(int i =0;i<nums.size();++i){
            if(i>=k){
                result.push_back(Q.front());
                if(nums[i-k]==Q.front()){
                    Q.pop_front();
                }
            }
            while(!Q.empty()&&Q.back()<nums[i]){
                    Q.pop_back();
                }
                Q.push_back(nums[i]);
        }
        if(!Q.empty())
            result.push_back(Q.front());
        return result;
    }
};

int main(){
    Solution S;
    vector<int> nums = {1,3,-1,-3,5,3,6,7};
    vector<int> D = S.maxSlidingWindow(nums,3);
    return 0;
}